// Copyright (C) Microsoft Corporation. All Rights Reserved.
// This code released under the terms of the
// Microsoft Limited Public License (Ms-LPL).

using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
using System.IO;
using System.Text;

using Microsoft.VisualStudio.IntelliTrace;
using Microsoft.VisualStudio.Samples.IHandlers;

namespace Microsoft.VisualStudio.Samples
{
	internal class ChainFormatter
	{
		
        private ThreadChainFormatter threadFormatter {get; set;}
        private TestChainFormatter testFormatter {get; set;}
        private ProcessChainFormatter processFormatter {get; set;}
        private MetadataChainFormatter metaFormatter {get; set;}
        private DiagnosticChainFormatter diagnosticFormatter {get; set;}
        private CheckpointChainFormatter checkpointFormatter {get; set;}

		public ChainFormatter(IntelliTraceProcess process)
		{
            threadFormatter = new ThreadChainFormatter(process);
            testFormatter = new TestChainFormatter(process);
            processFormatter = new ProcessChainFormatter(process);
            metaFormatter = new MetadataChainFormatter(process);
            diagnosticFormatter = new DiagnosticChainFormatter(process);
            checkpointFormatter = new CheckpointChainFormatter(process);
		}

        public bool Dump(IntelliTraceFile logFile, IntelliTraceProcess process)
		{
			metaFormatter.FireEvents();
            processFormatter.FireEvents();
            testFormatter.FireEvents();
            diagnosticFormatter.FireEvents();
            checkpointFormatter.FireEvents();
            foreach (IntelliTraceThread t in process.Threads)
			{
                threadFormatter.Thread = t;
                threadFormatter.FireEvents();
            }
			return false;
		}

        public void AddCheckpointEventHandler(CheckpointChainHandler handler)
        {
            checkpointFormatter.AddHandler(handler);
        }
        public void AddDiagnosticEventHandler(DiagnosticChainHandler handler)
        {
            diagnosticFormatter.AddHandler(handler);
        }
        public void AddTestEventHandler(TestChainHandler handler)
        {
            testFormatter.AddHandler(handler);
        }
        public void AddMetaDataEventHandler(MetadataChainHandler handler)
        {
            metaFormatter.AddHandler(handler);
        }
        public void AddProcessEventHandler(ProcessChainHandler handler)
        {
            processFormatter.AddHandler(handler);
        }
        public void AddThreadEventHandler(ThreadChainHandler handler)
        {
            threadFormatter.AddHandler(handler);
        }
    }
}
